/*
 * @lc app=leetcode.cn id=189 lang=golang
 *
 * [189] 轮转数组
 */

// @lc code=start
func rotate(nums []int, k int) {
	n := len(nums)
	k = k % n
	swap := func(i, j int) {
		nums[i], nums[j] = nums[j], nums[i]
	}
	reverse := func(l, r int) {
		for l < r {
			swap(l, r)
			l++
			r--
		}
	}
	reverse(0, n-1)
	reverse(0, k-1)
	reverse(k, n-1)
}

// @lc code=end

